<template>
  <!-- 金融产品清单 -->
  <div class="layout">
    <div class="financeProduct">
      <div style="display: flex; justify-content: center">
        <Breadcrumb class="breadcrumb" :crumbs="crumbs"></Breadcrumb>
      </div>
      <ProductBox @select="getDetailedPage"></ProductBox>
      <div class="productList">
        <div
          class="item"
          v-for="(item, index) in list"
          :key="index"
          @click="confinanDetail(item.companyFinancingId)"
        >
          <div class="label">
            <PublicImage
              v-if="!item.companyLogo"
              :src="require('@/assets/image/finance/product_dj.png')"
            ></PublicImage>
            <PublicImage
              v-else 
              :src="item.companyLogo"
            ></PublicImage>
          </div>
          <div class="content">
            <div class="textBox">
              <el-tooltip
                effect="dark"
                :content="item.companyName"
                placement="top"
              >
                <div class="textLeft">{{ item.companyName }}</div>
              </el-tooltip>
              <div class="textRight">{{ item.financingMoney }}万元</div>
            </div>
            <div class="titleBox"></div>
            <div class="textRig">
              <div class="textLeft">
                融资轮次：{{ getTurnVal(item.financingTurnVal) }}
              </div>
              <div class="textRight">
                {{ getStatusVal(item.financingStatusVal) }}
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id="policyPagination" v-if="total > 0">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          background
          :page-sizes="[12, 24, 36, 48]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { getFinancingSuccessPage } from "@/common/api/finance";

import Breadcrumb from "@/components/breadcrumb";
import ProductBox from "./components/productBox";
export default {
  data() {
    return {
      name: "finance",
      crumbs: [
        {
          label: "金融服务",
          value: "finance",
        },
        {
          label: "融资成功案例清单",
          value: "",
          choose: true,
        },
      ],
      types: [],
      turnList: [],
      statusList: [],
      typeIndex: -1,
      roundIndex: -1,
      list: [],
      pageNum: 1,
      pageSize: 12,
      total: 0,
    };
  },
  components: {
    Breadcrumb,
    ProductBox,
  },
  activated() {
    this.gettypeList();
    this.getDetailedPage();
  },
  computed: {
    getTurnVal() {
      return function (data) {
        let turnList = this.turnList;
        let obj = turnList.find((item) => item.dictValue == data);
        return obj && obj.dictLabel;
      };
    },
    getStatusVal() {
      return function (data) {
        let turnList = this.statusList;
        let obj = turnList.find((item) => item.dictValue == data);
        return obj && obj.dictLabel;
      };
    },
  },
  methods: {
    // 字典查询 政策类别
    async gettypeList() {
      // 调用公共方法中的查询字典表
      this.getDictList(
        this,
        `finance_financing_turn,policy_industry_type,finance_com_financing_status`
      ).then((res) => {
        //  融资的轮次
        if (res && res.finance_financing_turn) {
          this.turnList = res.finance_financing_turn;
        }
        this.types = res.policy_industry_type;
        this.statusList = res.finance_com_financing_status;
      });
    },
    // 金融产品清单列表
    async getDetailedPage(data) {
      let param = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        ...data,
      };
      let { code, msg, rows, total } = await getFinancingSuccessPage(param);
      if (code != "200") return this.$message.warning(msg);
      this.total = total;
      this.list = rows;
    },
    /**
     * 改变页面大小事件
     */
    handleSizeChange(e) {
      this.pageSize = e;
      this.getDetailedPage();
    },
    /**
     * 换页事件
     */
    handleCurrentChange(e) {
      this.pageNum = e;
      this.getDetailedPage();
    },
    // 企业金融服务 跳转到指定详情页
    confinanDetail(id) {
      let companyFinancingId = id;
      this.$router.push({
        path: "financeCaseDetail",
        query: {
          companyFinancingId,
        },
      });
    },
  },
};
</script>
<style scoped>
.financeProduct {
  width: 1200px;
  margin: 0 auto;
}
.breadcrumb {
  width: 1200px;
  margin: 20px 0;
}
.productList {
  display: flex;
  flex-wrap: wrap;
  margin-top: 50px;
  min-height: 20vh;
}
.productList .item {
  width: 282px;
  height: 310px;
  border: 1px solid #eeeeee;
  margin-bottom: 20px;
  background: #ffffff;
  box-shadow: 4px 6px 5px 0px rgba(0, 19, 39, 0.06);
  margin-right: 22px;
  cursor: pointer;
}
.productList .item:nth-child(4n) {
  margin-right: 0px;
}
.productList .item .label {
  height: 200px;
  background: #f4f4f4;
}
.productList .item .label img {
  width: 100%;
  height: 200px;
  object-fit: contain;
}
.productList .item .content {
  display: flex;
  flex-direction: column;
  text-align: left;
  margin: 20px;
}
.productList .item .content .titleBox {
  margin-top: 20px;
  font-size: 14px;
  color: #333;
}
.productList .item .content .textBox {
  display: flex;
  color: #999;
  font-size: 18px;
  justify-content: space-between;
}
.productList .item .content .textBox .textLeft {
  color: #333333;
  font-weight: bold;
  word-break: keep-all;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.productList .item .content .textBox .textRight {
  color: #ef6c22;
  font-weight: bold;
  flex-shrink: 0;
}
.productList .item .content .textRig {
  display: flex;
  color: #999;
  justify-content: space-between;
  font-size: 14px;
}
.productList .item .content .textRig span:last-child {
  margin-left: 20px;
}
.productList .item .btnBox {
  display: flex;
  justify-content: flex-end;
  margin-top: 15px;
  border-top: 1px solid #eeeeee;
}
.productList .item .btnBox .btn {
  width: 120px;
  height: 40px;
  line-height: 40px;
  background: #045db9;
  border-radius: 3px;
  color: #ffffff;
  margin-top: 10px;
  margin-right: 20px;
}
#policyPagination {
  text-align: right;
  margin-bottom: 30px;
}
</style>